package han.chensing.latos.maker.screen;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.ScreenUtils;

import han.chensing.latos.common.level.util.CacheHelper;
import han.chensing.latos.maker.GameMain;
import han.chensing.latos.maker.V;
import han.chensing.latos.maker.debug.Debug;
import han.chensing.latos.maker.res.Res;
import han.chensing.latos.maker.windows.dialog.base.BasicDialog;
import han.chensing.latos.maker.windows.menus.negative.NavigationBar;
import space.earlygrey.shapedrawer.ShapeDrawer;

public class MainScreen implements Screen {

    SpriteBatch batch;

    public void init(){
        batch = new SpriteBatch();
        V.container.addWindow(new BasicDialog("Welcome",
                """
                        Hi there!
                        Welcome to use LatosMaker by CCirno ~ CZH!
                        The version is in developing, so if you seen something went wrong
                        That it is not a bug, it is a feature! OvO"""));
        V.container.addWindow(new NavigationBar());
        GameMain.shapeDrawer =new ShapeDrawer(V.container.getStage().getBatch(), Res.get().get("shapeDrawerRegion", TextureRegion.class));
        GameMain.shapeDrawer.setDefaultLineWidth(2);
        Gdx.input.setInputProcessor(V.container.getStage());
        Debug.debugInMainScreenInit();
    }

    @Override
    public void show() {
    }

    @Override
    public void render(float delta) {
        ScreenUtils.clear(0.2f, 0.2f, 0.3f, 1);
        batch.begin();
        BitmapFont fontConsolas50 = Res.get().get("fontDeng", BitmapFont.class);
        fontConsolas50.draw(batch,"LatosMaker ~ CCirno", 1450,75,100,
                Align.center,false);
        fontConsolas50.draw(batch,"Indev build", 1450,50,100,
                Align.center,false);
        batch.end();
        V.container.act();
        V.container.draw();
        Gdx.gl.glEnable(GL20.GL_BLEND);
        Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    }

    @Override
    public void resize(int width, int height) {
        V.container.onResize(width,height);
    }

    @Override
    public void pause() {

    }

    @Override
    public void resume() {

    }

    @Override
    public void hide() {

    }

    @Override
    public void dispose() {
        Res.get().disposeAll();
        CacheHelper.getInstance().cleanFiles();
        batch.dispose();
        V.project.dispose();
        V.container.dispose();
    }
}
